/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mindwave.theoracle;

import org.neuroph.core.NeuralNetwork;
import org.neuroph.core.learning.DataSet;
import org.neuroph.core.learning.DataSetRow;
import org.neuroph.nnet.Perceptron;

/**
 *
 * @author MarcoJ
 */
public class NeuralOracle {

    private DataSet TrainingSet;
    private DataSet DataSet;
    NeuralNetwork neuralNetwork;
    double tempo = 0;
    double imgtmp = -1;
    boolean p3 = false;
    final int delay = 175;

    public NeuralOracle() {

        // create new perceptron network 
        neuralNetwork = new Perceptron(1, 1);
        // create training set 
        TrainingSet =
                new DataSet(1, 1);

    }

    public void addDataRowTraining(experienceBean inp, Figure f) {

        if (inp.getFigure() != f) {
            inp.setFigure(Figure.Spento);
        }
        addDataRow(inp);

    }

    public void addDataRow(experienceBean inp) {

        TrainingSet.addRow(new DataSetRow(new double[]{inp.getRaw()},
                new double[]{inp.getFigure().getCode()}));


    }

    public void saveNN(String path) {
        // save the trained network into file 
        neuralNetwork.save("Test//" + path + ".nnet");
    }

    public void loadNN(String path) {
        // save the trained network into file 
        neuralNetwork.load("Test//" + path + ".nnet");
    }

    public void learn() {

        // learn the training set 
        neuralNetwork.learn(TrainingSet);
    }

    public double setInputParameters(experienceBean inp) {

        // set network input 
        neuralNetwork.setInput(1);
        // calculate network 
        neuralNetwork.calculate();
        // get network output 
        double[] networkOutput = neuralNetwork.getOutput();

        return networkOutput[0];
    }
}
